from bs4 import BeautifulSoup
import requests
from urllib3.exceptions import InsecureRequestWarning

# 禁用InsecureRequestWarning警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


def check_proxy_ip(ip, port):
    # 检测IP的网址
    url = "https://www.cnblogs.com"

    # 请求头
    heeders = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
    }

    # 代理
    proxies = {
        "http": f"{ip}:{port}",
        "https": f"{ip}:{port}"
    }
    try:
        html = requests.get(url, headers=heeders, proxies=proxies,timeout=(3,3), verify=False).text
        bs = BeautifulSoup(html, "lxml")
        title = bs.title.text
        if title == "博客园 - 开发者的网上家园":
            return True

    except Exception:
        pass

#
# check_proxy_ip("47.122.65.254", "8080")





